package com.baosight.sczx.zm.cg.service;

import com.baosight.iplat4j.core.ei.EiBlock;
import com.baosight.iplat4j.core.ei.EiConstant;
import com.baosight.iplat4j.core.ei.EiInfo;
import com.baosight.iplat4j.core.threadlocal.UserSession;
import com.baosight.iplat4j.ep.ServiceEPBase;
import com.baosight.sczx.common.zm.basetools.StaticTools;
import com.baosight.sczx.common.zm.basetools.TablePk;
import com.baosight.sczx.common.zm.cInterface.Department;
import com.baosight.sczx.common.zm.cInterface.cs.WorkSchedule;
import com.baosight.sczx.zm.cg.domain.ZMCGDispatchDaily;
/**
 * 矿生产调度主表
 */
public class ServiceZMCG80 extends ServiceEPBase {
	/**
	 * <p>Function:initLoad</p>
	 * <p>Description: 初始化</p> 
	 */
	@Override
	public EiInfo initLoad(EiInfo inInfo) {
		inInfo.addBlock(EiConstant.resultBlock).set("showCount", "true");//如果不加这个，翻页的统计和显示是错误的
		EiInfo outInfo = this.query(inInfo);
//		String fdMiningName= (String)UserSession.getInSessionProperty("miningName");
//		outInfo.set("fdDepartmentId", UserSession.getInSessionProperty("miningCode"));// 矿ID的默认值
//		outInfo.set("fdMiningName", UserSession.getInSessionProperty("miningName"));// 矿名称的默认值
		return outInfo;
	}	
	
	/**
	 * <p>Function: query</p>
	 * <p>Description: 查询</p>
	 * <p>return value: ServiceZMCG80</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-10-21下午03:26:59 张小飞
	 *    
	 *    
	 * </p>
	 *
	 */
	@Override
	public EiInfo query(EiInfo inInfo) {//inqu_status
		String fdVirtualDate = (String)inInfo.getString("fdVirtualDate");
		if(fdVirtualDate == null) {
			fdVirtualDate = StaticTools.getDate();
			StaticTools.setQueryParameters(inInfo, "fdVirtualDate", fdVirtualDate, true);
		}
		String fdMiningId= (String)UserSession.getInSessionProperty("miningCode");
		StaticTools.setQueryParameters(inInfo, "fdMiningId", fdMiningId, true);
		EiInfo outInfo = super.query(inInfo, "ZMCGDispatchDaily.query", new ZMCGDispatchDaily());
		outInfo.set("fdMiningId", UserSession.getInSessionProperty("miningCode"));// 矿名称的默认值
		outInfo.setCell("inqu_status", 0, "fdMiningId", fdMiningId);
		outInfo.addBlock(WorkSchedule.getWorkScheduleBlock("cmes.cg.workNum", fdMiningId, true));
		outInfo.addBlock(Department.getInstance().getMiningDepts("cmes.cg.department", "orgCode", "orgName", true, fdMiningId));
		return outInfo;
	}
	/**
	 * 新增
	 * <p>Function: insert</p>
	 * <p>Description: </p>
	 * <p>return value: ServiceZMCP70</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-7-6下午03:58:15 张志芳
	 * </p>
	 *
	 */ 
	@Override
	public EiInfo insert(EiInfo inInfo) {	
		EiInfo out=new EiInfo();
		ZMCGDispatchDaily _dom = new ZMCGDispatchDaily();
		EiBlock eiBlock = inInfo.getBlock("result");
		eiBlock.setBlockMeta(_dom.eiMetadata);
		int rowcount = eiBlock.getRowCount();
		int i = 0;		
		for (; i < rowcount; i++) {
			_dom.fromMap(eiBlock.getRow(i));	
			_dom.setFdKeyId(TablePk.getInstance().getNextValue("T_CG_DISPATCHDAILY"));//主键			
			this.dao.insert("ZMCGDispatchDaily.insert", _dom);
		}		
		out = this.query(inInfo);
		out.setStatus(1);
		out.setMsg("操作" + rowcount + "记录成功");
		return out; 	
			
	}
} 